<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_bufferAnalyst2"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.text_bufferAnalyst2"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_addPath" onclick="addPath()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_bufferAnalyst" onclick="bufferAnalystProcess()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_query" onclick="queryByGeometry()"/>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_removeResult" onclick="clearElements()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var  map, layer, vectorLayer, resultLayer, markerLayer, gpsLine, bufferResultGeometry,
        myPointsList = [new SuperMap.Geometry.Point(2823.940, -4690.000),
            new SuperMap.Geometry.Point(3448.940, -4690.301),
            new SuperMap.Geometry.Point(3816.561, -3810.125),
            new SuperMap.Geometry.Point(3917.383, -3609.158),
            new SuperMap.Geometry.Point(3976.983, -3490.291),
            new SuperMap.Geometry.Point(4020.004, -4377.027),
            new SuperMap.Geometry.Point(4076.265, -4382.939),
            new SuperMap.Geometry.Point(4215.049, -4382.333),
            new SuperMap.Geometry.Point(4428.156, -4382.285),
            new SuperMap.Geometry.Point(4647.579, -4383.017),
            new SuperMap.Geometry.Point(4679.707, -4382.898),
            new SuperMap.Geometry.Point(4917.462, -4382.635),
            new SuperMap.Geometry.Point(5074.019, -4381.833),
            new SuperMap.Geometry.Point(5257.042, -4381.031),
            new SuperMap.Geometry.Point(5363.785, -4380.717),
            new SuperMap.Geometry.Point(5671.717, -4378.794),
            new SuperMap.Geometry.Point(5847.521, -4377.970),
            new SuperMap.Geometry.Point(5990.637, -4303.528),
            new SuperMap.Geometry.Point(6055.343, -4270.072),
            new SuperMap.Geometry.Point(6168.913, -4382.389),
            new SuperMap.Geometry.Point(6214.183, -4209.927),
            new SuperMap.Geometry.Point(6377.789, -4209.142),
            new SuperMap.Geometry.Point(6393.692, -4210.142),
            new SuperMap.Geometry.Point(6693.989, -4207.450),
            new SuperMap.Geometry.Point(6788.392, -4208.450),
            new SuperMap.Geometry.Point(6984.304, -4207.210),
            new SuperMap.Geometry.Point(7189.183, -4208.296),
            new SuperMap.Geometry.Point(7300.505, -4208.296),
            new SuperMap.Geometry.Point(7573.056, -4208.803),
            new SuperMap.Geometry.Point(7680.977, -4208.804),
            new SuperMap.Geometry.Point(7850.593, -4208.393),
            new SuperMap.Geometry.Point(8182.656, -4210.533),
            new SuperMap.Geometry.Point(8554.893, -4261.485)],
        myFeatures = [],
        stylePoint = {
            strokeColor: "black",
            strokeOpacity: 1,
            strokeDashstyle: "solid",
            fillColor: "black",
            pointRadius: 2
        },
        styleLine = {
            strokeColor: "red",
            strokeWidth: 2,
            pointRadius: 3,
            pointerEvents: "visiblePainted",
            fill: false
        },
        styleRegion = {
            strokeColor: "#304DBE",
            strokeWidth: 2,
            pointerEvents: "visiblePainted",
            fillColor: "#304DBE",
            fillOpacity: 0.4
        },
        url = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
        url2 = host + "/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";
    init();

    function init() {
        vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
        resultLayer = new SuperMap.Layer.Vector("Result Layer");
        markerLayer = new SuperMap.Layer.Markers("Markers Layer");
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })], units: "m"
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("Changchun", url, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});
        for (var i = 0; i < myPointsList.length; i++) {
            myFeature = new SuperMap.Feature.Vector();
            myFeature.geometry = myPointsList[i];
            myFeature.style = stylePoint;
            myFeatures.push(myFeature);
        }
        vectorLayer.addFeatures(myFeatures);
    }

    function addLayer() {
        map.addLayers([layer, vectorLayer, resultLayer, markerLayer]);
        map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 0);
    }

    //将离散gps信号点生成线路
    function addPath() {
        widgets.alert.clearAlert();
        var pathFeature = new SuperMap.Feature.Vector();
        gpsLine = new SuperMap.Geometry.LineString(myPointsList);
        pathFeature.geometry = gpsLine;
        pathFeature.style = styleLine;
        resultLayer.addFeatures(pathFeature);
    }

    //对生成的线路进行缓冲区分析
    function bufferAnalystProcess() {
        widgets.alert.clearAlert();
        if (!gpsLine) {
            widgets.alert.showAlert(resources.msg_addPath,true);
            return;
        }
        var bufferServiceByGeometry = new SuperMap.REST.BufferAnalystService(url2),
            bufferDistance = new SuperMap.REST.BufferDistance({
                value: 250
            }),
            bufferSetting = new SuperMap.REST.BufferSetting({
                endType: SuperMap.REST.BufferEndType.ROUND,
                leftDistance: bufferDistance,
                rightDistance: bufferDistance,
                semicircleLineSegment: 10
            }),
            geoBufferAnalystParam = new SuperMap.REST.GeometryBufferAnalystParameters({
                sourceGeometry: gpsLine,
                bufferSetting: bufferSetting
            });

        bufferServiceByGeometry.events.on(
            {
                "processCompleted": bufferAnalystCompleted
            });
        bufferServiceByGeometry.processAsync(geoBufferAnalystParam);
    }

    function bufferAnalystCompleted(BufferAnalystEventArgs) {
        var feature = new SuperMap.Feature.Vector();
        bufferResultGeometry = BufferAnalystEventArgs.result.resultGeometry;
        feature.geometry = bufferResultGeometry;
        feature.style = styleRegion;
        resultLayer.addFeatures(feature);
    }

    //查询出信号影响范围内的工厂
    function queryByGeometry() {
        widgets.alert.clearAlert();
        if (!bufferResultGeometry) {
            widgets.alert.showAlert(resources.msg_bufferAnalyst,false);
            return;
        }
        var queryParam, queryByGeometryParameters, queryService;
        queryParam = new SuperMap.REST.FilterParameter({name: "Company@Changchun.2"});
        queryByGeometryParameters = new SuperMap.REST.QueryByGeometryParameters({
            queryParams: [queryParam],
            geometry: bufferResultGeometry,
            spatialQueryMode: SuperMap.REST.SpatialQueryMode.INTERSECT
        });
        queryService = new SuperMap.REST.QueryByGeometryService(url);
        queryService.events.on(
            {
                "processCompleted": queryCompleted
            });
        queryService.processAsync(queryByGeometryParameters);
    }

    function queryCompleted(queryEventArgs) {
        var i, j, result = queryEventArgs.result;
        if (result && result.recordsets) {
            for (i = 0, recordsets = result.recordsets, len = recordsets.length; i < len; i++) {
                if (recordsets[i].features) {
                    for (j = 0; j < recordsets[i].features.length; j++) {
                        var point = recordsets[i].features[j].geometry,
                            size = new SuperMap.Size(44, 40),
                            offset = new SuperMap.Pixel(-(size.w / 2), -size.h),
                            icon = new SuperMap.Icon("./images/marker-gold.png", size, offset);
                        markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon));
                    }
                }
            }
        }
    }

    function clearElements() {
        widgets.alert.clearAlert();
        gpsLine = null;
        bufferResultGeometry = null;
        resultLayer.removeAllFeatures();
        markerLayer.clearMarkers();
    }

</script>

</body>
</html>